package cn.dapeng.ticket;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class Ticket_Demo06 {

    /**
     * 原则：在多线程的情况下，少用set list 多用queue
     * 而且queue的效率高
     */

    public final static Queue<String> queue = new ConcurrentLinkedQueue<>();

    static {
        for (int i = 0; i < Constant.TICKET_NUM; i++) {
            queue.add("ticket-num:" + i);
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < Constant.THREAD_NUM; i++) {
            new Thread(() -> {
                while (!queue.isEmpty()) {
                    String ticket = queue.poll();
                    System.out.println(ticket);
                }
            }).start();
        }
    }
}
